package com.training.hatton.dropboxclient.processor.common;

import java.text.MessageFormat;

import org.apache.http.client.methods.HttpRequestBase;

import android.os.ResultReceiver;

import com.training.hatton.base.RequestDataWrapper;
import com.training.hatton.base.processor.BaseProcessor;
import com.training.hatton.dropboxclient.utill.DropboxService;

public abstract class DropboxBaseProcessor<T> extends BaseProcessor<T>{

	public DropboxBaseProcessor(RequestDataWrapper dataWrapper, ResultReceiver resultReceiver) {
		super(dataWrapper, resultReceiver);
	}


	private static final String SIGN_TEMPLATE = "OAuth oauth_version=\"1.0\", oauth_signature_method=\"PLAINTEXT\", oauth_consumer_key=\"{0}\",oauth_token=\"{1}\",oauth_signature=\"{2}&{3}\"";
	
	private static final String AUTHORIZATION = "Authorization";

	
	public static void sign(HttpRequestBase request) {
		String headerValue = MessageFormat
				.format(SIGN_TEMPLATE, 
						DropboxService.APP_KEY, 
						DropboxService.getAccess_token(), 
						DropboxService.APP_SECRET, 
						DropboxService.getAccess_token_secret());
		request.addHeader(AUTHORIZATION, headerValue);
	}

}